#include "VGCVirtualGameConsole.h"
#include "CImageEntity.h"
#include "CVector.h"
#include "CImage.h"

using namespace std;

CImageEntity::CImageEntity(CImage image, double x, double y):
	CEntity(x, y),
	image(image),
	frameDuration(0.25) {}

CImageEntity::~CImageEntity() {}

void CImageEntity::setImage(CImage image) {
	this->image = image;
}

CImage CImageEntity::getImage() {
	return this->image;
}

double CImageEntity::getFrameDuration() {
	return this->frameDuration;
}

int CImageEntity::frameIndexX(const double &time) {
	return (int) (time / getFrameDuration()) % getImage().getFrameCountX();
}

int CImageEntity::frameIndexY(const double &time) {
	return 0;
}

void CImageEntity::draw(const double &time) {
	getImage().drawFrame(
		VGCVector(frameIndexX(time), frameIndexY(time)),
		getPosition(), getAdjustment());
}

void CImageEntity::destroy() {
	getImage().destroy();
}